package ModelSimple;



import java.util.Random;

import Contoller.Main;

public class MonteCarloCalSimpleThread extends Thread {
	
	private double Resutl;
	private double Time;
	private double dt;
	private double Sum;
	private double Drift;
	private double vSqrdt;
	private double S;
	private double i=0;
	private Integer j=0;
	private Integer z;
	private double X;
	private double r;
	private double T;
	private Integer nSteps;
    private Integer nSimulation;
	
	
	public MonteCarloCalSimpleThread(String CallPutFlag,double S,double T,double r,double b, double v
			,Integer nSteps, Integer nSimulation,double X)
	{
		//on charge les données qui seront utilisé.
		this.S=S;
		this.X=X;
		this.nSteps=nSteps;
		this.nSimulation=nSimulation;
		this.dt = T / nSteps;
		this.Drift = (b -  java.lang.Math.pow(v,2) / 2) * dt;
		this.vSqrdt = v * java.lang.Math.sqrt(dt);
		this.r=r;
		this.T=T;
		if(CallPutFlag == "c")
		{
		this.z = 1;
		}
		else if(CallPutFlag == "p")
		{
		this.z = -1;
		}
		
		
	}
	
	public void CalculOneThread()
	{
		Random rand = new Random() ;
		double St=0;
		
		//calcul formule de monte carlo
		for(this.i=1;i<=this.nSimulation;i++)
		{
			
			St = this.S ;
			for(this.j=1;this.j<=this.nSteps;this.j++)
			{
			
		    St = St * Math.exp(this.Drift + this.vSqrdt * rand.nextGaussian());
		 
			}
			
			
			this.Sum = this.Sum + Math.max(this.z*(St-this.X),0);
			//accéder à progress1 et la modifier au fur & a mesure
			Main.GUI.jProgressBar2.setValue((int) i);
		}
		
		 this.setResutl(java.lang.Math.exp((-this.r) * this.T)*(this.Sum/this.nSimulation));
		 
	}
	
	
	
	
	
	
	
	

	public double getResutl() {
		return Resutl;
	}

	private void setResutl(double resutl) {
		Resutl = resutl;
	}

	public double getTime() {
		return Time;
	}
	
	
	
}
